package day15;

import com.alibaba.fastjson.JSON;
import day14.Product;

import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class JSonTostr {
    public static void main(String[] args) {
//        List<Product> datas=new ArrayList<>();
////        datas.add(new Product(1,"恰恰瓜子",5.7,"袋",200));
////        datas.add(new Product(2,"凤爪",7.7,"袋",50));
////        datas.add(new Product(3,"旺旺刨冰",9,"袋",56));
////        datas.add(new Product(4,"卫龙辣条",2,"袋",8));
////        Object json= JSON.toJSON(datas);
////        System.out.println(json);
        String str="[{\"no\":1,\"unit\":\"袋\",\"price\":5.7,\"name\":\"恰恰瓜子\",\"stockCount\":200},{\"no\":2,\"unit\":\"袋\",\"price\":7.7,\"name\":\"凤爪\",\"stockCount\":50},{\"no\":3,\"unit\":\"袋\",\"price\":9.0,\"name\":\"旺旺刨冰\",\"stockCount\":56},{\"no\":4,\"unit\":\"袋\",\"price\":2.0,\"name\":\"卫龙辣条\",\"stockCount\":8}]";
        List<Product> products =  JSON.parseArray(str,Product.class);
        for(Product p:products)
            System.out.println(p);
    }
}
